package com.ruitu.health.fragment;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.github.jdsjlzx.recyclerview.LRecyclerView;
import com.ruitu.arad.base.base_list.ListBaseAdapter;
import com.ruitu.arad.base.base_list.SuperViewHolder;
import com.ruitu.arad.support.widget.progress.ProgressLayout;
import com.ruitu.arad.util.ScreenUtils;
import com.ruitu.arad.util.SizeUtils;
import com.ruitu.arad.util.ToastUtils;
import com.ruitu.health.R;
import com.ruitu.router_module.bean.product.ProHome;
import com.ruitu.router_module.support.view.BaseRefreshGridFragment;

import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.RecyclerView;

public class HomeProFragment extends BaseRefreshGridFragment {
    private HomeProListAdapter adapter;
    private List<ProHome> proHomeList = new ArrayList<>();

    public static HomeProFragment newInstance() {
        Bundle args = new Bundle();
        HomeProFragment fragment = new HomeProFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected int getLayoutRes() {
        return R.layout.fragment_home_pro;
    }

    @Override
    protected void initViews(View v) {
        for (int i = 0; i < 10; i++) {
            ProHome pro = new ProHome();
            proHomeList.add(pro);
        }
        adapter.setDataList(proHomeList);

    }

    @Override
    protected void initRecyclerView(View v) {
        super.initRecyclerView(v);
//        lAdapter.removeHeaderView();
    }

    @Override
    protected void onItemClick(View v, int pos) {
        super.onItemClick(v, pos);
        ToastUtils.showShortSafe("pos = " + pos);
    }

    @Override
    protected LRecyclerView findRecyclerView(View v) {
        return v.findViewById(R.id.lrcv_list);
    }

    @Override
    protected RecyclerView.Adapter initAdapter() {
        adapter = new HomeProListAdapter(getActivity());
        return adapter;
    }

    @Override
    protected void reqFirst() {

    }

    @Override
    protected void reqMore() {
        ToastUtils.showShortSafe("加载更多...");
    }

    private class HomeProListAdapter extends ListBaseAdapter<ProHome> {

        public HomeProListAdapter(Context context) {
            super(context);
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_home_tab_pro;
        }

        @Override
        public void onBindItemHolder(SuperViewHolder holder, int position) {
            ImageView icon = holder.getView(R.id.icon);// 商品的图片

            int width = ScreenUtils.getScreenWidth();
            int itemWidth = (width - SizeUtils.dp2px(30)) / 2;

            RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) icon.getLayoutParams();
            params.width = itemWidth;
            params.height = itemWidth * 10 / 16;
            icon.setLayoutParams(params);
        }
    }

    @Override
    protected ProgressLayout findProgressLayout(View v) {
        return null;
    }
}
